package com.egdigital.allzic.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.egdigital.allzic.R;

public class AdapterGridHome extends BaseAdapter {

	// log
	private static final String	TAG			= AdapterGridAllzic.class.getSimpleName();
	// data
	private static final int	SIZE		= 4;
	private LayoutInflater		mInflater	= null;
	private Context				mContext;

	private class CellHolderGridHome {

		private ImageView	mImage;
		private TextView	mText;
	}

	public AdapterGridHome(Context context) {
		mContext = context;
		mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return SIZE;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// get
		convertView = mInflater.inflate(R.layout.cell_grid_home, parent, false);
		CellHolderGridHome cellHolder = new CellHolderGridHome();
		cellHolder.mImage = (ImageView) convertView.findViewById(R.id.cell_grid_allzic_image);
		cellHolder.mText = (TextView) convertView.findViewById(R.id.cell_grid_allzic_label);
		// set
		switch (position) {
			case 0: // allzic
				cellHolder.mImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.home_allzic));
				cellHolder.mText.setText(mContext.getString(R.string.activity_home_allzic));
				break;
			case 1:// category
				cellHolder.mImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.home_categories));
				cellHolder.mText.setText(mContext.getString(R.string.activity_home_category));
				break;
			case 2:// explorer
				cellHolder.mImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.home_explorer));
				cellHolder.mText.setText(mContext.getString(R.string.activity_home_explorer));
				break;
			case 3:// favoris
				cellHolder.mImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.home_favoris));
				cellHolder.mText.setText(mContext.getString(R.string.activity_home_favorite));
				break;
		}
		YoYo.with(Techniques.FadeIn).duration((500 * position) + 500).playOn(convertView); // animation zoomin
		// end
		convertView.setTag(cellHolder);
		return convertView;
	}
}